package org.example.wechat.controller;

import jakarta.servlet.http.HttpSession;
import org.example.wechat.config.ResponseBodyMessage;
import org.example.wechat.mapper.FriendMapper;
import org.example.wechat.mapper.UserMapper;
import org.example.wechat.model.Friend;
import org.example.wechat.model.User;
import org.example.wechat.tools.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/friend")
public class FriendController {
    @Autowired
    FriendMapper friendMapper;
    @Autowired
    UserMapper userMapper;
    @RequestMapping("/selectFriend")
    public ResponseBodyMessage<List<User>> selectFriend(HttpSession session){
        List<User> users = new ArrayList<>();
        List<Friend> friends = friendMapper.selectFriendList(1);
        for (Friend f:friends) {
            User u = userMapper.selectUserByUserId(f.getFriendId());
            System.out.println(u.getId() + "   - " + u.getName());
            users.add(u);
        }
        return new ResponseBodyMessage<>(200,"查询成功",users);
    }
}
